{$CLEO .cs}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP 

script_name "StWCan"

// By ArtemQa146

wait 500

:LoadedModels
wait 500
0AF0: 1@ = read_int_from_ini_file "cleo\StreetCleaners.ini" section "Models" key "Loaded3"
if
1@ == 1
jf @LoadedModels
1@ = 0 
0AF1: write_int 1@ to_ini_file "cleo\StreetCleaners.ini" section "Models" key "Loaded3"

0AF0: 0@ = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Settings" key "Street Cleaners"
if
    0@ == 0
then
    0A93: terminate_this_custom_script
end

0AF0: 6@ = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Street Cleaners" key "Ped ID Watercan"
0AF0: 31@ = read_int_from_ini_file "cleo\StreetCleaners.ini" section "Models" key "Wcan"

if
    6@ <= 0
then
    6@ = 225
end

// 1@ actor
// 0@ render
// 5@ particle
// 6@ Ped ID from ini

:WCan
wait 150
if 
   Player.Defined($PLAYER_CHAR)
jf @WCan
if and
$ACTIVE_INTERIOR == 0  
$ONMISSION == 0 
jf @WCan
0D59: get_current_weather_to 3@
0E40: get_current_hour 2@
if and
not 3@ == 8 // not weather rain 
not 3@ == 16 // not weather rain 2
2@ >= 6
14 >= 2@
jf @WCan

// LS

:WCan_Coords_1 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1183.682 -2058.9353 69.0078 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1183.682 -2058.9353 69.0078 radius 50.0
jf @WCan_Coords_2
// coords to walk 
10@ = 1183.682  
11@ = -2058.9353
12@ = 69.0078

13@ = 1183.5918  
14@ = -2051.5127
15@ = 69.0078

16@ = 1166.9873  
17@ = -2051.3745
18@ = 69.0078

19@ = 1167.0402  
20@ = -2057.6802
21@ = 69.0078

22@ = 1167.0953  
23@ = -2022.9348
24@ = 69.0006

25@ = 1183.5793  
26@ = -2021.8389
27@ = 69.0078

28@ = 1183.6348  
29@ = -2016.6753
30@ = 69.0078
jump @WCan_Start

:WCan_Coords_2 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2030.2227 -1210.9197 22.1561 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2030.2227 -1210.9197 22.1561 radius 50.0
jf @WCan_Coords_3
// coords to walk 
10@ = 2030.2227 
11@ = -1210.9197
12@ = 22.1561

13@ = 2021.3118  
14@ = -1214.8311
15@ = 21.6883

16@ = 2023.1991  
17@ = -1179.3279
18@ = 22.0921

19@ = 2016.0564  
20@ = -1175.0924
21@ = 21.7332

22@ = 2042.5314  
23@ = -1160.2657
24@ = 23.1522

25@ = 2048.5747  
26@ = -1161.9352
27@ = 23.4273

28@ = 2025.8734  
29@ = -1208.5745
30@ = 22.1106
jump @WCan_Start

:WCan_Coords_3 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 569.9189 -1232.7014 17.5851 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 569.9189 -1232.7014 17.5851 radius 50.0
jf @WCan_Coords_4 
// coords to walk 
10@ = 569.9189  
11@ = -1232.7014
12@ = 17.5851

13@ = 556.1456  
14@ = -1239.2667
15@ = 17.2416

16@ = 546.2946 
17@ = -1244.7349 
18@ = 16.9627

19@ = 538.638  
20@ = -1250.0568
21@ = 16.7432

22@ = 581.2889  
23@ = -1228.0258
24@ = 17.8019

25@ = 538.239  
26@ = -1250.4325
27@ = 16.7314

28@ = 561.6109  
29@ = -1237.0767
30@ = 17.3737
jump @WCan_Start

:WCan_Coords_4 
wait 100
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1446.0077 -2307.6616 13.5469 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1446.0077 -2307.6616 13.5469 radius 50.0
jf @WCan_Coords_5
// coords to walk 
10@ = 1446.0077  
11@ = -2307.6616
12@ = 13.5469

13@ = 1442.1273  
14@ = -2297.491
15@ = 13.5469

16@ = 1444.125 
17@ = -2292.519 
18@ = 13.5469

19@ = 1442.542  
20@ = -2280.7075
21@ = 13.5469

22@ = 1442.3624  
23@ = -2274.697
24@ = 13.5469

25@ = 1445.0824  
26@ = -2268.1301
27@ = 13.5469

28@ = 1440.99  
29@ = -2292.8135
30@ = 13.5469
jump @WCan_Start

// LV

:WCan_Coords_5 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2143.9167 1680.0983 10.8203 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2143.9167 1680.0983 10.8203 radius 50.0
jf @WCan_Coords_6
// coords to walk 
10@ = 2143.9167  
11@ = 1680.0983
12@ = 10.8203

13@ = 2120.4946  
14@ = 1675.3247
15@ = 10.8203

16@ = 2113.0254  
17@ = 1675.8372
18@ = 10.8203

19@ = 2091.1531 
20@ = 1681.251
21@ =  10.8203

22@ = 2114.304  
23@ = 1691.231
24@ = 10.8203

25@ = 2121.8069  
26@ = 1691.0547
27@ = 10.8203

28@ = 2090.4373  
29@ = 1686.0167
30@ = 10.8203
jump @WCan_Start

:WCan_Coords_6 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1110.4316 1056.9075 10.2666 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1110.4316 1056.9075 10.2666 radius 50.0
jf @WCan_Coords_7
// coords to walk 
10@ = 1110.4316  
11@ = 1056.9075
12@ = 10.2666 

13@ = 1113.3339  
14@ = 1084.5568
15@ = 10.2214

16@ = 1107.4077  
17@ = 1097.9185
18@ = 10.2651 

19@ = 1115.5471 
20@ = 1105.4275
21@ = 10.2234

22@ = 1098.2186   
23@ = 1049.3102
24@ = 10.2178

25@ = 1105.6729   
26@ = 1040.8461
27@ = 10.2634

28@ = 1120.6608   
29@ = 1045.0627
30@ = 10.2486
jump @WCan_Start

:WCan_Coords_7
wait 100
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1486.2983 -350.9649 14.9016 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1486.2983 -350.9649 14.9016 radius 50.0
jf @WCan
// coords to walk
10@ = -1486.2983 
11@ = -350.9649
12@ = 14.9016

13@ = -1469.2848 
14@ = -359.6387
15@ = 14.8781

16@ = -1454.502 
17@ = -349.7907
18@ = 14.6164

19@ = -1471.7649 
20@ = -314.21
21@ = 14.1448

22@ = -1462.6146 
23@ = -336.7379
24@ = 14.5435

25@ = -1453.8518 
26@ = -323.304
27@ = 14.133

28@ = -1439.2046 
29@ = -337.9026
30@ = 14.138
jump @WCan_Start



:WCan_Start 
Model.Load(6@)
if
    not model.Available(6@)
then
    repeat
    wait 0
    model.Load(6@)
    until model.Available(6@)
end
038B: load_requested_models 

repeat
wait 0
04ED: load_animation  "PedEventsMod"
until 04EE:   animation "PedEventsMod" loaded

Actor.Create(1@, 21, 6@, 10@, 11@, 12@)   
0E24: fix_char 1@ ground 1 brightness 1 and_fade_in 0 
0F02:  1@ special_model 31@ bone 24 offset 0 0 0 rotation 0 0 0 scale 0@ // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 0@ dead 1 weapon 1 car 1
0669: 5@ = create_attached_particle "prt_watersplash" on_actor 1@ with_offset 0.496 -0.021 0.9 flag 1 
0883: attach_particle 5@ to_actor 1@ mode 24
0AC1: 7@ = load_audio_stream_with_3d_support "SQ/WaterCan.mp3" // IF and SET
0AC4: link_3d_audio_stream 7@ to_actor 1@
0ABC: set_audio_stream 7@ volume 0.0
Model.destroy(6@)

while true
wait 0
if
    056D:   actor 1@ defined
then
    if and
        0EE4: locate_char_distance_to_char $PLAYER_ACTOR char 1@ radius 150.0
        $ACTIVE_INTERIOR == 0
    then
    
        0EFF: get_char_simplest_active_task 1@ id_to 2@ pointer_to 4@
        if and
            2@ == 203 // task stand still
            not Actor.Animation(1@) == "WaterCan"
        then
            if or
                00FE:   actor 1@ sphere 0 in_sphere 10@ 11@ 12@ radius 2.0 2.0 2.0
                00FE:   actor 1@ sphere 0 in_sphere 13@ 14@ 15@ radius 2.0 2.0 2.0
                00FE:   actor 1@ sphere 0 in_sphere 16@ 17@ 18@ radius 2.0 2.0 2.0
                00FE:   actor 1@ sphere 0 in_sphere 19@ 20@ 21@ radius 2.0 2.0 2.0
                00FE:   actor 1@ sphere 0 in_sphere 22@ 23@ 24@ radius 2.0 2.0 2.0
                00FE:   actor 1@ sphere 0 in_sphere 25@ 26@ 27@ radius 2.0 2.0 2.0
                00FE:   actor 1@ sphere 0 in_sphere 28@ 29@ 30@ radius 2.0 2.0 2.0
            then
                0605: actor 1@ perform_animation "WaterCan" IFP "PedEventsMod" framedelta 2.0 loop 1 lockX 0 lockY 0 lockF 0 time -1
                wait 100
                0AAD: set_audio_stream 7@ state 1
                0AC0: audio_stream 7@ looped 1
                continue
            end
        end

        if
            not Actor.Animation(1@) == "WaterCan"
        then
            0AAD: set_audio_stream 7@ state 0
        end
            
        if
            0EE4: locate_char_distance_to_char $PLAYER_ACTOR char 1@ radius 20.0
        then
            0ABC: set_audio_stream 7@ volume 0.4
        else
            0ABC: set_audio_stream 7@ volume 0.0
        end
            
        if
            Actor.Animation(1@) == "WaterCan"
        then
            gosub @Animation
            continue
        end

        0D59: get_current_weather_to 3@
        0E40: get_current_hour 4@
        080E: get_actor 1@ ped_event_to 2@
        if or
            0118:   actor 1@ dead
            3@ == 8 // not weather rain
            3@ == 16 // not weather rain 2
            4@ >= 16 // timeout
            2@ == 9 // ped damaged
            2@ == 49 // shoot close ped
        then
            0AAE: remove_audio_stream 7@
            0650: destroy_particle 5@
            if
                056D:   actor 1@ defined
            then
                01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
            end
            04EF: release_animation "PedEventsMod"
            jump @WCan
        end
        
        080E: get_actor 1@ ped_event_to 2@
        if or
            2@ == 15
            2@ == 31
            2@ == 59
        then
            0AAE: remove_audio_stream 7@
            0650: destroy_particle 5@
            if
                056D:   actor 1@ defined
            then
                01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
            end
            04EF: release_animation "PedEventsMod"
            jump @WCan
        end
        
            //    
            if
                0457:   player $PLAYER_CHAR aiming_at_actor 1@
            then
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
                0E89: get_weaponinfo_fire_type 2@ store_to 3@ //     
                if or
                    3@ == 1 //  
                    3@ == 3 //   (  ..)
                then
                    0AAE: remove_audio_stream 7@
                    0650: destroy_particle 5@
                    if
                        056D:   actor 1@ defined
                    then
                        01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
                    end
                    04EF: release_animation "PedEventsMod"
                    jump @WCan
                end
            end
        
        else
            gosub @Remove
            wait 1000
            jump @WCan
        end
    else
        gosub @Remove
        wait 1000
        jump @WCan
    end
end

:Remove
0AAE: remove_audio_stream 7@
0650: destroy_particle 5@
if
    056D:   actor 1@ defined
then
    009B: destroy_actor 1@
end
04EF: release_animation "PedEventsMod"
return


:Animation
0613: 4@ = actor 1@ animation "WaterCan" time

// particle
if
    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char 1@ radius 20.0
then
    0EC0: add_fx_system_particle 5@ coord 0.4 0.04 0.28 vel 0 0 0 size 0.1 brightness 0 rgba 0.8 0.8 0.9 0.2 lastFactor 0.7
end

// if animation ended, walk another position
if
    4@ >= 0.95
then
    0209: 2@ = random_int_in_ranges 1 30 // random walk
    0208: 4@ = random_float_in_ranges 0.0 360.0
    if
        2@ == 1
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 10@ 11@ 12@ stop_with_angle 4@ within_radius 1.0
    end
    if
        2@ == 2
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 13@ 14@ 15@ stop_with_angle 4@ within_radius 1.0
    end
    if
        2@ == 3
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 16@ 17@ 18@ stop_with_angle 4@ within_radius 1.0
    end
    if
        2@ == 4
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 19@ 20@ 21@ stop_with_angle 4@ within_radius 1.0
    end
    if
        2@ == 5
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 22@ 23@ 24@ stop_with_angle 4@ within_radius 1.0
    end
    if
        2@ == 6
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 25@ 26@ 27@ stop_with_angle 4@ within_radius 1.0
    end
    if
        2@ == 7
    then
        0AAD: set_audio_stream 7@ state 0
        07CD: AS_actor 1@ walk_to 28@ 29@ 30@ stop_with_angle 4@ within_radius 1.0
    end

    if
        2@ >= 8
    then
        wait 1000 // for animation again
    end

    wait 100
end
return

// By ArtemQa146